package com.sgb.kjwl.viewmodel.enterprise;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.NeedDetailsEntity;
import com.sgb.kjwl.model.entity.enterprise.NeedDetailSignUpEntity;
import com.swgk.core.base.model.entity.BaseEntity;

import org.jetbrains.annotations.NotNull;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SignUpDetailViewModel extends AndroidViewModel {

    public MutableLiveData<NeedDetailSignUpEntity> data = new MutableLiveData<>();
    public MutableLiveData<String> ToastShow = new MutableLiveData<>();
    //1show,2dismiss
    public MutableLiveData<Integer> showloading = new MutableLiveData<>();


    public NeedDetailSignUpEntity mItemData = null;
    public NeedDetailsEntity needData = null;

    public SignUpDetailViewModel(@NonNull @NotNull Application application) {
        super(application);
    }




    public void getDetail(){


        showloading.postValue(1);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getSignUpDetail(mItemData.getId()+"").enqueue(new Callback<BaseEntity<NeedDetailSignUpEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<NeedDetailSignUpEntity>> call, Response<BaseEntity<NeedDetailSignUpEntity>> response) {
                showloading.postValue(2);
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    data.postValue(response.body().getData());
                } else {
                    ToastShow.postValue(response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<NeedDetailSignUpEntity>> call, Throwable t) {
                showloading.postValue(2);
                ToastShow.postValue(t.getMessage());
            }
        });

    }
}
